//
//  MIDIMymedalController.m
//  迷笛
//
//  Created by . on 2018/9/10.
//  Copyright © 2018年 🍃🌺🌺🍃. All rights reserved.
//

#import "MIDIMymedalController.h"
#import "MIDImedalCell.h"
@interface MIDIMymedalController ()<UICollectionViewDataSource,UICollectionViewDelegate>
{
    NSArray * arr;
}
@property (nonatomic,strong) UIView *headerView;
@property(nonatomic,strong)UILabel * integral;
@property(nonatomic,strong)UIButton * rules;
@property(nonatomic,strong)UIImageView * imagee;
@end

@implementation MIDIMymedalController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor =[UIColor grayColor];

    arr = @[@"IMG_6297.jpg",@"IMG_6297.jpg",@"IMG_6297.jpg",@"IMG_6297.jpg",@"IMG_6297.jpg",@"IMG_6297.jpg",@"IMG_6297.jpg",@"IMG_6297.jpg"];
    
    
    UIBarButtonItem *leftBarItem = [[UIBarButtonItem alloc] initWithTitle:nil style:UIBarButtonItemStylePlain target:self action:@selector(Block:)];
    self.navigationItem.leftBarButtonItem = leftBarItem;
    
    [self.navigationItem.leftBarButtonItem setImage:[[UIImage imageNamed:@"后退"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [self Collection];
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    
    return 10;
}

// 单元格内容
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    MIDImedalCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MyCell" forIndexPath:indexPath];
    // 设置显示数据
//    cell.backgroundColor =[UIColor colorWithHexString:@"#1B212F"];
    cell.img.image = [UIImage imageNamed:@"obtain"];
    cell.Lv.text = @"LEVEL1";
    
    return cell;
    
}
//  返回头视图
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    static NSString *headerViewIdentifier = @"hederview";
    
    //如果是头视图
    if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
        UICollectionReusableView *header=[collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:headerViewIdentifier forIndexPath:indexPath];
        //添加头视图的内容
        [self addContent];
        //头视图添加view
        [header addSubview:self.headerView];
        return header;
    }
    //如果底部视图
    //    if([kind isEqualToString:UICollectionElementKindSectionFooter]){
    //
    //    }
    return nil;
}



-(void)Collection
{
    // 创建流布局对象 (保存设定的样式规则)
    UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];
    // 设定单元格的大小
    flow.itemSize = CGSizeMake(110, 170);
    // 设定滚动方向
    flow.scrollDirection = UICollectionViewScrollDirectionVertical;
    // 最小列间距
    flow.minimumInteritemSpacing = WidthScale(10);
    // 最小行间距
    flow.minimumLineSpacing = kDevice_Is_iPhoneX?HeighX(10):HeightScale(10);
    // 设定分区的边距
    flow.sectionInset = UIEdgeInsetsMake(WidthScale(28), WidthScale(45), WidthScale(90), WidthScale(45));
    
    
    // 创建网格对象，用流布局对象进行初始化
    UICollectionView *collect = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) collectionViewLayout:flow];
    // 设定代理关系
    collect.dataSource = self;
    collect.delegate = self;
    
    collect.pagingEnabled = NO;
    collect.backgroundColor = [UIColor colorWithHexString:@"#1B212F"];
    // 将网格加入到视图上显示
    [self.view addSubview:collect];
    // 为网格注册单元格类
    [collect registerClass:[MIDImedalCell class] forCellWithReuseIdentifier:@"MyCell"];
    
    static NSString *headerViewIdentifier = @"hederview";
    
    flow.headerReferenceSize=CGSizeMake(self.view.frame.size.width, kDevice_Is_iPhoneX?HeighX(215):HeightScale(215));
    [collect registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headerViewIdentifier];
}
-(void)addContent
{
    UIImageView *header=[[UIImageView alloc]init];
    header.frame=CGRectMake(0, 0, self.view.frame.size.width, kDevice_Is_iPhoneX?HeighX(215):HeightScale(215));
    header.image = [UIImage imageNamed:@"medal"];
    self.headerView=header;
    [self.headerView addSubview:self.imagee];
    [self.imagee mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(WidthScale(50));
        make.centerX.equalTo(self.headerView);
        make.width.mas_offset(WidthScale(70));
        make.height.mas_offset(kDevice_Is_iPhoneX?HeighX(70):HeightScale(70));
    }];
    [self.headerView addSubview:self.integral];
    [self.integral mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.imagee);
        make.top.equalTo(self.imagee.mas_bottom).offset(WidthScale(15));
       [self.integral setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    }];
    [self.headerView addSubview:self.rules];
    [self.rules mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_offset(WidthScale(-10));
        make.top.equalTo(self.headerView).offset(WidthScale(10));
        make.width.mas_offset(WidthScale(90));
        make.height.mas_offset(kDevice_Is_iPhoneX?HeighX(20):HeightScale(20));
    }];
    
}
-(UIImageView *)imagee
{
    if (!_imagee)
    {
        _imagee =[[UIImageView alloc]init];
        _imagee.image =[UIImage imageNamed:@"IMG_0195.jpg"];
        _imagee.layer.masksToBounds = YES;
        [_imagee.layer setCornerRadius:WidthScale(35)]; //设置矩圆角半径
    }
    return _imagee;
}
-(UILabel *)integral
{
    if (!_integral)
    {
        _integral =[[UILabel alloc]init];
        _integral.text = @"当前积分：77";
        _integral.textColor = [UIColor colorWithHexString:@"#FFFFFF"];
        _integral.font =[UIFont systemFontOfSize:WidthScale(15)];
    }
    return _integral;
}
-(UIButton *)rules
{
    if (!_rules)
    {
        _rules =[[UIButton alloc]init];
        [_rules setTitle:@"查看积分规则" forState:0];
        [_rules setTitleColor:[UIColor colorWithHexString:@"#FF005D"] forState:0];
        _rules.titleLabel.font =[UIFont systemFontOfSize:WidthScale(12)];
    }
    return _rules;
}

// 返回上一级
-(void)Block:(UIButton * )sender
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = YES;
    self.navigationController.navigationBar.translucent = NO;//Bar的模糊效果，默认为YES

    self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:@"#171717"];
    self.title = @"我的勋章";
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#FFFFFF"],NSFontAttributeName : [UIFont fontWithName:@"Helvetica-Bold" size:WidthScale(17)]}];    //    去掉导航黑线
    UIImage *img = [UIImage imageNamed:@""];
    [self.navigationController.navigationBar setBackgroundImage:img  forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
}


@end
